#include "key.h"

void key_init()
{
    gpio_config_t key_init_struct = {0};

    key_init_struct.pin_bit_mask = 1ULL << BOOT_GPIO_PIN;
    key_init_struct.mode = GPIO_MODE_INPUT;
    key_init_struct.intr_type = GPIO_INTR_DISABLE;
    key_init_struct.pull_down_en = GPIO_PULLDOWN_DISABLE;
    key_init_struct.pull_up_en = GPIO_PULLUP_ENABLE;

    gpio_config(&key_init_struct);
}

uint8_t key_scan(uint8_t mode)
{
    uint8_t keyVal=0;
    static uint8_t key_boot = 1;

    if(mode==1)
    {
        key_boot=1;
    }

    if (BOOT == BOOT_PRES)
    {
        vTaskDelay(pdMS_TO_TICKS(10));
        if (BOOT == BOOT_PRES && key_boot==1)
        {
            key_boot=0;
            keyVal=BOOT_PRES;
        }
    }
    else
    {
        key_boot=1;
    }
    return keyVal;
}